<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:body>
    <ui:composition template="/resources/templates/default.xhtml">
        <ui:define name="title">Logs</ui:define>
        <ui:define name="titlePage"><h:form id="titleForm">#{logsBean.viewName} du #{logsBean.daySelected} #{logsCalendarBean.getMonthNameOf(logsBean.monthSelected)} #{logsBean.yearSelected} <h:outputText value="à #{logsBean.hourSelected}h" rendered="#{logsBean.hourSelected &gt; 0}"/><h:outputText value="à minuit" rendered="#{logsBean.hourSelected eq 0}"/></h:form></ui:define>
        <ui:define name="cssStyle"> 
            <style>
                .divlogs{
                    padding-left: 30px;
                }
                
                .divlogs a{
                    font-weight:bold;
                    text-indent: 10px;
                    color:forestgreen;
                    text-decoration: none;
                    transition: ease-in-out 250ms;
                    margin: 5px;
                }
                
                .divlogs a:hover{
                    color:lime;
                }
                
                .divlogs-content{
                    border:1px solid gray;
                    border-radius: 5px;
                }
                
                .divlogs-title{
                    font-size: 28px;
                    font-weight: bold;
                    padding-top: 5px;
                    padding-bottom: 5px;
                    text-indent: 5px;
                    border-bottom: 1px solid gray;
                    background:lightgray;
                }
                .dataTableLog input{
                    width:40px;
                }
                
                .ui-datatable .ui-column-filter{
                    width:90%;
                }
            </style>
        </ui:define>
        <ui:define name="content">
            <p:ajaxStatus onstart="PF('statusDialog').show()" onsuccess="PF('statusDialog').hide()" />
            <p:layout>
                <p:layoutUnit position="north">
                    <p:panel header="Heures">
                        <p:toolbar>
                            <f:facet name="left">
                                <h:form id="changeHourForm">
                                    <p:selectOneButton id="selectHour" value="#{logsBean.hourSelected}"> 
                                        <f:selectItem itemLabel="Tout" itemValue="-1"/>
                                        <f:selectItems value="#{logsBean.hoursInDayLog}" var="hidl" itemLabel="#{hidl.hourLog}h" itemValue="#{hidl.hourLog}"/>
                                        <p:ajax update=":viewShowForm,:titleForm,:changeViewForm" listener="#{logsBean.handleChangeHour()}" />
                                    </p:selectOneButton>
                                </h:form>
                            </f:facet>
                            <f:facet name="right">
                                <h:form id="changeViewForm">
                                    <p:selectOneButton id="selectView" value="#{logsBean.viewSelected}">
                                        <f:selectItem id="ddd" itemLabel="Logs" itemValue="1" itemDisabled="#{logsBean.hourSelected eq -1}" />
                                        <f:selectItem itemLabel="Top site" itemValue="2" />
                                        <p:ajax update=":viewShowForm,:titleForm" listener="#{logsBean.handleChange()}" />
                                    </p:selectOneButton>
                                </h:form>
                            </f:facet>
                        </p:toolbar>
                    </p:panel>
                </p:layoutUnit>
                <p:layoutUnit position="center">
                    <h:form id="viewShowForm">
                        <p:panel rendered="#{logsBean.viewSelected eq 1}">
                            <p:panel style="font-weight:bold;">#{logsBean.logs.size()} log(s).</p:panel>
                            <p:dataTable id="dataToExport" styleClass="dataTableLog" filteredValue="#{logsBean.listeLogFilter}" paginator="true" rows="200" var="l" emptyMessage="Aucun logs" value="#{logsBean.logs}">
                                <p:column sortBy="#{l.atTime}" filterBy="#{l.timeString}" headerText="Heure" style="width:50px; text-align: center;">
                                    <h:outputText value="#{l.timeString}"/>
                                </p:column>
                                <p:column headerText="NOM/PRENOM" style="width:120px; text-align: center;">
                                    <h:commandLink rendered="#{l.idEtudiant != -1}" action="logs/student" actionListener="#{logsBean.changeEtudiantSelectedByID(l.idEtudiant)}" value="#{l.nomEtudiant} #{l.prenomEtudiant}">
                                        <f:setPropertyActionListener target="#{topSitesBean.domainSelected}" value="#{null}" />
                                    </h:commandLink>
                                    <h:outputText value="#{l.nomEtudiant} #{l.prenomEtudiant}" rendered="#{l.idEtudiant eq -1}"/>
                                </p:column>
                                <p:column headerText="IP" style="width:90px; text-align: center;">
                                    <a target="_blank" href="#{l.ip}">#{l.ip}</a>
                                </p:column>
                                <p:column headerText="URL" style="word-break: break-all;">
                                    <a target="_blank" href="#{l.url}">#{l.url}</a>
                                </p:column>
                                <p:column sortBy="#{l.requestSize}" style="width:75px; text-align: center;" headerText="SIZE">
                                    <h:outputText value="#{l.sizeConverted}"/>
                                </p:column>
                                <p:column sortBy="#{l.mimeType}" filterBy="#{l.mimeType}" style="width:100px; text-align: center;" headerText="MIMETYPE">
                                    <h:outputText value="#{l.mimeType}"/>
                                </p:column>
                            </p:dataTable>
                        </p:panel>
                        <p:panel rendered="#{logsBean.viewSelected eq 2}">
                            <p:panel style="font-weight:bold;">#{topSitesBean.topsite.size()} site(s) ont été visité.</p:panel>
                            <p:dataTable var="ts" emptyMessage="Aucun site" value="#{topSitesBean.topsite}">
                                <p:column sortBy="#{ts.visites}" headerText="VISITES" style="width:50px; text-align: center;">
                                    #{ts.visites}
                                </p:column>
                                <p:column headerText="DOMAINE" sortBy="#{ts.domaine}">
                                    <h:commandLink action="logs/topsite_users" value="#{ts.domaine}">
                                        <f:setPropertyActionListener target="#{topSitesBean.domainSelected}" value="#{ts.domaine}" />
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="DATASIZE" sortBy="#{ts.dataSize}">
                                    #{topSitesBean.convertDataSize(ts)}
                                </p:column>
                            </p:dataTable>
                        </p:panel>
                    </h:form>
                </p:layoutUnit>
            </p:layout>
        </ui:define>
        <ui:define name="dialogs">
            <p:dialog widgetVar="statusDialog" modal="true" draggable="false" closable="false" resizable="false" showHeader="false">
                <p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
            </p:dialog>
        </ui:define>
    </ui:composition>
    </h:body>
</html>
